package com.dqyt.khjc.service;

import com.dqyt.khjc.bean.CityBean;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.mapper.CityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CityService {

    @Autowired
    private CityMapper cityMapper;

    /**
     * 获取城市列表
     * @return
     */
    public ResultMsg getCityList(){

        ResultMsg ret = new ResultMsg(); // 声明一个返回值
        try{
            List<CityBean> mlist =  cityMapper.getCityList();
            if(null  == mlist){
                ret.setData(new ArrayList<CityBean>());
                ret.setCode(ResultMsg.SUCESS);
            }else{
                ret.setData(mlist);
                ret.setCode(ResultMsg.SUCESS);
            }
        }catch (Exception e){
            ret.setCode(ResultMsg.ERROR);
            ret.setMsg("未知的错误，请稍候再试！");
            e.printStackTrace();
        }
        return ret;
    }

}
